package test

import config.MyFile

object test2 extends MyFile{

  def main(args: Array[String]): Unit = {
    val gff = "D:\\大豆基因组数据库\\mcscanx_v2/soyhome.gff".readLines.map{x=>
      val line = x.split("\t")
      line(1) -> (line(2).toInt,line(3).toInt)
    }.toMap


    val range ="D:\\大豆基因组数据库\\mcscanx_v2/soyhome.collinearity".readFileToString.split("## ").drop(3)
    val row = range.map{x=>
      val line = x.split("\n")
      val head = line.head.split(" ")
      val score = head.find(_.startsWith("score")).get.drop(7)
      val e_value = head.find(_.startsWith("e_value")).get.drop(8)
      val N =head.find(_.startsWith("N")).get.drop(2)
      val chr = head(head.length-2)
      val query = chr.split("&").head
      val ref = chr.split("&").last
      val id = head(1).init
      val block = query.take(2)+"_vs_" + ref.take(2)

      val genes = line.tail.map{g=>
        val l = g.split("\t")
        val query =gff(l(1))
        val ref = gff(l(2))
        (query._1,query._2,ref._1,ref._2)
      }
      val queryStart = genes.map(_._1).min
      val queryEnd = genes.map(_._2).max
      val refStart = genes.map(_._3).min
      val refEnd = genes.map(_._4).max


      (id.toInt,block,query,queryStart,queryEnd,ref,refStart,refEnd,score,e_value,N)
    }.groupBy(_._2).flatMap{x=>
      x._2.sortBy(_._1).zipWithIndex.map{y=>
        (0,y._1._2 + "_" +( y._2+1),y._1._3,y._1._4,y._1._5,y._1._6,y._1._7,y._1._8,y._1._9,y._1._10,y._1._11)
      }.toSeq
    }.foreach(println)

  }
}
